package com.example.nonggo.presenter;

import com.example.nonggo.Constants;
import com.example.nonggo.base.BasePresenter;
import com.example.nonggo.bean.ConditionRes;
import com.example.nonggo.contract.LoginContract;
import com.example.nonggo.contract.WeatherContract;
import com.example.nonggo.model.HomeModel;
import com.example.nonggo.model.WeatherModel;
import com.tencent.mmkv.MMKV;

public class WeatherPresenter extends BasePresenter<WeatherContract> {

    private final WeatherModel weatherModel;

    public WeatherPresenter(WeatherModel weatherModel) {
        this.weatherModel = weatherModel;
    }

    public void getConditionData(String province, String city, String county){
        weatherModel.getCondition(province, city, county, new WeatherContract.Presenter() {
            @Override
            public void getConditionSuccess(ConditionRes data) {
                String temp = data.getCondition().getTemp();
                String condition = data.getCondition().getCondition();
                String  icon  = data.getCondition().getIcon();
                MMKV.defaultMMKV().putString(Constants.CONDITION,condition);
                MMKV.defaultMMKV().putString(Constants.UPDATE_TIME,data.getCondition().getUpdatetime());
                MMKV.defaultMMKV().putString(Constants.WEATHER_LOGO,icon);
                MMKV.defaultMMKV().putString(Constants.TEMP,temp);
                MMKV.defaultMMKV().putString(Constants.PRECIPITATION,data.getCondition().getPrecipitation());
                MMKV.defaultMMKV().putString(Constants.WIND_DIR, data.getCondition().getWindDir());
                MMKV.defaultMMKV().putString(Constants.WIND_SPEED,data.getCondition().getWindSpeed());
                getView().getConditionSuccess(temp,condition,icon);
            }
        });
    }
}
